# Copyright 2019 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# NOTE: This file is auto generated by the elixir code generator program.
# Do not edit this file manually.

defmodule GoogleApi.Firestore.V1.Model.Target do
  @moduledoc """
  A specification of a set of documents to listen to.

  ## Attributes

  *   `documents` (*type:* `GoogleApi.Firestore.V1.Model.DocumentsTarget.t`, *default:* `nil`) - A target specified by a set of document names.
  *   `expectedCount` (*type:* `integer()`, *default:* `nil`) - The number of documents that last matched the query at the resume token or read time. This value is only relevant when a `resume_type` is provided. This value being present and greater than zero signals that the client wants `ExistenceFilter.unchanged_names` to be included in the response.
  *   `once` (*type:* `boolean()`, *default:* `nil`) - If the target should be removed once it is current and consistent.
  *   `query` (*type:* `GoogleApi.Firestore.V1.Model.QueryTarget.t`, *default:* `nil`) - A target specified by a query.
  *   `readTime` (*type:* `DateTime.t`, *default:* `nil`) - Start listening after a specific `read_time`. The client must know the state of matching documents at this time.
  *   `resumeToken` (*type:* `String.t`, *default:* `nil`) - A resume token from a prior TargetChange for an identical target. Using a resume token with a different target is unsupported and may fail.
  *   `targetId` (*type:* `integer()`, *default:* `nil`) - The target ID that identifies the target on the stream. Must be a positive number and non-zero. If `target_id` is 0 (or unspecified), the server will assign an ID for this target and return that in a `TargetChange::ADD` event. Once a target with `target_id=0` is added, all subsequent targets must also have `target_id=0`. If an `AddTarget` request with `target_id != 0` is sent to the server after a target with `target_id=0` is added, the server will immediately send a response with a `TargetChange::Remove` event. Note that if the client sends multiple `AddTarget` requests without an ID, the order of IDs returned in `TargetChange.target_ids` are undefined. Therefore, clients should provide a target ID instead of relying on the server to assign one. If `target_id` is non-zero, there must not be an existing active target on this stream with the same ID.
  """

  use GoogleApi.Gax.ModelBase

  @type t :: %__MODULE__{
          :documents => GoogleApi.Firestore.V1.Model.DocumentsTarget.t() | nil,
          :expectedCount => integer() | nil,
          :once => boolean() | nil,
          :query => GoogleApi.Firestore.V1.Model.QueryTarget.t() | nil,
          :readTime => DateTime.t() | nil,
          :resumeToken => String.t() | nil,
          :targetId => integer() | nil
        }

  field(:documents, as: GoogleApi.Firestore.V1.Model.DocumentsTarget)
  field(:expectedCount)
  field(:once)
  field(:query, as: GoogleApi.Firestore.V1.Model.QueryTarget)
  field(:readTime, as: DateTime)
  field(:resumeToken)
  field(:targetId)
end

defimpl Poison.Decoder, for: GoogleApi.Firestore.V1.Model.Target do
  def decode(value, options) do
    GoogleApi.Firestore.V1.Model.Target.decode(value, options)
  end
end

defimpl Poison.Encoder, for: GoogleApi.Firestore.V1.Model.Target do
  def encode(value, options) do
    GoogleApi.Gax.ModelBase.encode(value, options)
  end
end
